#{extends 'main.html' /}
#{set title:'Passenger' /}

#{if passenger.id}
    <b>${passenger.flight.fetch()}</b><br/><br/>
#{/if}

<form method="post">

    #{authenticityToken /}
    
    <input type="hidden" name="passenger.id" value="${passenger.str()}"/>

    <div class="fields">

        <table>

            #{field 'passenger.firstName'}
                <tr class="field ${field.errorClass}">
                    <td class="label"><label for="firstName">&{'passenger.firstName'}:</label></td>
                    <td class="field"><input id="firstName" type="text" name="${field.name}" value="${passenger.firstName}" class="large"/></td>
                    <td>#{ifError field.name}<span class="error">${field.error}</span>#{/ifError}</td>
                </tr>
            #{/field}

            #{field 'passenger.lastName'}
            <tr class="field ${field.errorClass}">
                <td class="label"><label for="lastName">&{'passenger.lastName'}:</label></td>
                <td class="field"><input id="lastName" type="text" name="${field.name}" value="${passenger.lastName}" class="large"/></td>
                <td>#{ifError field.name}<span class="error">${field.error}</span>#{/ifError}</td>
            </tr>
            #{/field}

            #{if !passenger.id}
                #{field 'passenger.flight'}
                    <tr class="field ${field.errorClass}">
                        <td class="label"><label for="flight">&{'passenger.flight'}:</label></td>
                        <td class="field">
                            <select id="flight" name="${field.name}">
                                <option value="" ${passenger.flight == null ? 'selected' : ''}>&{'notSpecified'}</option>
                                #{list flights, as:'flight'}
                                <option value="${flight.str()}" ${passenger.flight?.id == flight.id ? 'selected' : ''}>${flight}</option>
                                #{/list}
                            </select>
                        </td>
                        <td>#{ifError field.name}<span class="error">${field.error}</span>#{/ifError}</td>
                    </tr>
                #{/field}
            #{/if}

        </table>

    </div>

    <div>
        <input type="submit" value="&{'passenger.save'}" />
        #{if passenger.flight}<a href="@{index(passenger.flight.id)}">&{'cancel'}</a>#{/if}
        #{if !passenger.flight}<a href="@{index()}">&{'cancel'}</a>#{/if}
    </div>

</form>